home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / WIN_XY.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  6.8 KB  |  290 lines

  1. // win_xy.c -- windows specific xy view code
  2.  
  3. #include "stdafx.h"
  4. #include "qe3.h"
  5.  
  6. static HDC   s_hdcXY;
  7. static HGLRC s_hglrcXY;
  8.  
  9. static unsigned s_stipple[32] =
  10. {
  11.     0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  12.     0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  13.     0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  14.     0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  15.     0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  16.     0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  17.     0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  18.     0xaaaaaaaa, 0x55555555,0xaaaaaaaa, 0x55555555,
  19. };
  20.  
  21. /*
  22. ============
  23. WXY_WndProc
  24. ============
  25. */
  26. LONG WINAPI XYWndProc (
  27.     HWND    hWnd,
  28.     UINT    uMsg,
  29.     WPARAM  wParam,
  30.     LPARAM  lParam)
  31. {
  32.     int        fwKeys, xPos, yPos;
  33.     RECT    rect;
  34.  
  35.  
  36.     GetClientRect(hWnd, &rect);
  37.  
  38.     switch (uMsg)
  39.     {
  40.     case WM_CREATE:
  41.  
  42.     s_hdcXY = GetDC(hWnd);
  43.         QEW_SetupPixelFormat(s_hdcXY, false);
  44.  
  45.         if ( ( s_hglrcXY = wglCreateContext( s_hdcXY ) ) == 0 )
  46.             Error( "wglCreateContext in WXY_WndProc failed" );
  47.  
  48.         if (!wglMakeCurrent( s_hdcXY, s_hglrcXY ))
  49.             Error ("wglMakeCurrent failed");
  50.  
  51.         if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcXY ) )
  52.             Error( "wglShareLists in WXY_WndProc failed" );
  53.  
  54.         glPolygonStipple ((unsigned char *)s_stipple);
  55.         glLineStipple (3, 0xaaaa);
  56.  
  57.         return 0;
  58.  
  59.     case WM_DESTROY:
  60.         QEW_StopGL( hWnd, s_hglrcXY, s_hdcXY );
  61.         return 0;
  62.  
  63.     case WM_PAINT:
  64.         { 
  65.             PAINTSTRUCT    ps;
  66.  
  67.             BeginPaint(hWnd, &ps);
  68.  
  69.             if (!wglMakeCurrent( s_hdcXY, s_hglrcXY ))
  70.                 Error ("wglMakeCurrent failed");
  71.  
  72.             QE_CheckOpenGLForErrors();
  73.             XY_Draw ();
  74.             QE_CheckOpenGLForErrors();
  75.  
  76.             SwapBuffers(s_hdcXY);
  77.  
  78.             EndPaint(hWnd, &ps);
  79.         }
  80.         return 0;
  81.  
  82.     case WM_KEYDOWN:
  83.         return QE_KeyDown (wParam);
  84.         
  85.     case WM_MBUTTONDOWN:
  86.     case WM_RBUTTONDOWN:
  87.     case WM_LBUTTONDOWN:
  88.         if ( GetTopWindow( g_qeglobals.d_hwndMain ) != hWnd)
  89.             BringWindowToTop(hWnd);
  90.         SetFocus( g_qeglobals.d_hwndXY );
  91.         SetCapture( g_qeglobals.d_hwndXY );
  92.         fwKeys = wParam;        // key flags 
  93.         xPos = (short)LOWORD(lParam);  // horizontal position of cursor 
  94.         yPos = (short)HIWORD(lParam);  // vertical position of cursor 
  95.         yPos = (int)rect.bottom - 1 - yPos;
  96.         XY_MouseDown (xPos, yPos, fwKeys);
  97.         return 0;
  98.  
  99.     case WM_MBUTTONUP:
  100.     case WM_RBUTTONUP:
  101.     case WM_LBUTTONUP:
  102.         fwKeys = wParam;        // key flags 
  103.         xPos = (short)LOWORD(lParam);  // horizontal position of cursor 
  104.         yPos = (short)HIWORD(lParam);  // vertical position of cursor 
  105.         yPos = (int)rect.bottom - 1 - yPos;
  106.         XY_MouseUp (xPos, yPos, fwKeys);
  107.         if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  108.             ReleaseCapture ();
  109.         return 0;
  110.  
  111.     case WM_MOUSEMOVE:
  112.     if (::GetFocus() != hWnd)
  113.       ::SetFocus(hWnd);
  114.         fwKeys = wParam;        // key flags 
  115.         xPos = (short)LOWORD(lParam);  // horizontal position of cursor 
  116.         yPos = (short)HIWORD(lParam);  // vertical position of cursor 
  117.         yPos = (int)rect.bottom - 1 - yPos;
  118.         XY_MouseMoved (xPos, yPos, fwKeys);
  119.         return 0;
  120.  
  121.     case WM_SIZE:
  122.         g_qeglobals.d_xy.width = rect.right;
  123.         g_qeglobals.d_xy.height = rect.bottom - 16;
  124.         InvalidateRect( g_qeglobals.d_hwndXY, NULL, false);
  125.         return 0;
  126.  
  127.     case WM_NCCALCSIZE:// don't let windows copy pixels
  128.         DefWindowProc (hWnd, uMsg, wParam, lParam);
  129.         return WVR_REDRAW;
  130.  
  131.     case WM_KILLFOCUS:
  132.     case WM_SETFOCUS:
  133.         SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
  134.         return 0;
  135.  
  136.        case WM_CLOSE:
  137.         DestroyWindow (hWnd);
  138.         return 0;
  139.     }
  140.  
  141.     return DefWindowProc (hWnd, uMsg, wParam, lParam);
  142. }
  143.  
  144.  
  145. /*
  146. ==============
  147. WXY_Create
  148. ==============
  149. */
  150. void WXY_Create (HINSTANCE hInstance)
  151. {
  152.   ASSERT(0);
  153. #if 0
  154.     WNDCLASS   wc;
  155.  
  156.     /* Register the camera class */
  157.     memset (&wc, 0, sizeof(wc));
  158.  
  159.     wc.style         = CS_NOCLOSE;
  160.     wc.lpfnWndProc   = (WNDPROC)WXY_WndProc;
  161.     wc.cbClsExtra    = 0;
  162.     wc.cbWndExtra    = 0;
  163.     wc.hInstance     = hInstance;
  164.     wc.hIcon         = 0;
  165.     wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
  166.     wc.hbrBackground = NULL; //(HBRUSH)(COLOR_WINDOW+1);
  167.     wc.lpszMenuName  = NULL;
  168.     wc.lpszClassName = XY_WINDOW_CLASS;
  169.  
  170.     if (!RegisterClass (&wc) )
  171.         Error ("RegisterClass: failed");
  172.  
  173.     g_qeglobals.d_hwndXY = CreateWindow (XY_WINDOW_CLASS ,
  174.         "XY View",
  175.         QE3_STYLE ,
  176.         ZWIN_WIDTH,
  177.         (int)(screen_height*CWIN_SIZE)-20,
  178.         screen_width-ZWIN_WIDTH,
  179.         (int)(screen_height*(1.0-CWIN_SIZE)-38),    // size
  180.  
  181.         g_qeglobals.d_hwndMain,    // parent
  182.         0,        // no menu
  183.         hInstance,
  184.         NULL);
  185.  
  186.     if (!g_qeglobals.d_hwndXY )
  187.         Error ("Couldn't create XY View");
  188.  
  189.     LoadWindowState(g_qeglobals.d_hwndXY, "xywindow");
  190.     ShowWindow(g_qeglobals.d_hwndXY, SW_SHOWDEFAULT);
  191. #endif
  192. }
  193.  
  194. static void WXY_InitPixelFormat( PIXELFORMATDESCRIPTOR *pPFD )
  195. {
  196.     memset( pPFD, 0, sizeof( *pPFD ) );
  197.  
  198.     pPFD->nSize    = sizeof( PIXELFORMATDESCRIPTOR );
  199.     pPFD->nVersion = 1;
  200.     pPFD->dwFlags  = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
  201.     pPFD->iPixelType = PFD_TYPE_RGBA;
  202.     pPFD->cColorBits = 24;
  203.     pPFD->cDepthBits = 32;
  204.     pPFD->iLayerType = PFD_MAIN_PLANE;
  205.  
  206. }
  207.  
  208. void WXY_Print( void )
  209. {
  210.     DOCINFO di;
  211.  
  212.     PRINTDLG pd;
  213.  
  214.     /*
  215.     ** initialize the PRINTDLG struct and execute it
  216.     */
  217.     memset( &pd, 0, sizeof( pd ) );
  218.     pd.lStructSize = sizeof( pd );
  219.     pd.hwndOwner = g_qeglobals.d_hwndXY;
  220.     pd.Flags = PD_RETURNDC;
  221.     pd.hInstance = 0;
  222.     if ( !PrintDlg( &pd ) || !pd.hDC )
  223.     {
  224.         MessageBox( g_qeglobals.d_hwndMain, "Could not PrintDlg()", "QE4 Print Error", MB_OK | MB_ICONERROR );
  225.         return;
  226.     }
  227.  
  228.     /*
  229.     ** StartDoc
  230.     */
  231.     memset( &di, 0, sizeof( di ) );
  232.     di.cbSize = sizeof( di );
  233.     di.lpszDocName = "QE4";
  234.     if ( StartDoc( pd.hDC, &di ) <= 0 )
  235.     {
  236.         MessageBox( g_qeglobals.d_hwndMain, "Could not StartDoc()", "QE4 Print Error", MB_OK | MB_ICONERROR );
  237.         return;
  238.     }
  239.  
  240.     /*
  241.     ** StartPage
  242.     */
  243.     if ( StartPage( pd.hDC ) <= 0 )
  244.     {
  245.         MessageBox( g_qeglobals.d_hwndMain, "Could not StartPage()", "QE4 Print Error", MB_OK | MB_ICONERROR );
  246.         return;
  247.     }
  248.  
  249.     /*
  250.     ** read pixels from the XY window
  251.     */
  252.     {
  253.         int bmwidth = 320, bmheight = 320;
  254.         int pwidth, pheight;
  255.  
  256.         RECT r;
  257.  
  258.         GetWindowRect( g_qeglobals.d_hwndXY, &r );
  259.  
  260.         bmwidth  = r.right - r.left;
  261.         bmheight = r.bottom - r.top;
  262.  
  263.         pwidth  = GetDeviceCaps( pd.hDC, PHYSICALWIDTH ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETX );
  264.         pheight = GetDeviceCaps( pd.hDC, PHYSICALHEIGHT ) - GetDeviceCaps( pd.hDC, PHYSICALOFFSETY );
  265.  
  266.         StretchBlt( pd.hDC,
  267.             0, 0,
  268.             pwidth, pheight,
  269.             s_hdcXY,
  270.             0, 0,
  271.             bmwidth, bmheight,
  272.             SRCCOPY );
  273.     }
  274.  
  275.     /*
  276.     ** EndPage and EndDoc
  277.     */
  278.     if ( EndPage( pd.hDC ) <= 0 )
  279.     {
  280.         MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndPage()", MB_OK | MB_ICONERROR );
  281.         return;
  282.     }
  283.  
  284.     if ( EndDoc( pd.hDC ) <= 0 )
  285.     {
  286.         MessageBox( g_qeglobals.d_hwndMain, "QE4 Print Error", "Could not EndDoc()", MB_OK | MB_ICONERROR );
  287.         return;
  288.     }
  289. }
  290.